package com.gemme.gemme.login;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;

import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;

import com.gemme.gemme.MainActivity;
import com.gemme.gemme.R;
import com.gemme.gemme.manager.DataManager;
import com.gemme.gemme.util.asrsa.RsaNewUtils;
import com.gemme.gemme.view.LoginView;
import com.hyphenate.chat.ChatClient;

import java.security.PrivateKey;
import java.security.PublicKey;

public class LoginActivity extends AppCompatActivity {
   Context context =  LoginActivity.this;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
////        getData();
        initView();
        judge();
        requestPemission();
    }

    private void requestPemission() {
        if(Build.VERSION.SDK_INT>=23){
            String[] mPermissionList = new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE,Manifest.permission.ACCESS_FINE_LOCATION,Manifest.permission.CALL_PHONE,Manifest.permission.READ_LOGS,Manifest.permission.READ_PHONE_STATE, Manifest.permission.READ_EXTERNAL_STORAGE,Manifest.permission.SET_DEBUG_APP,Manifest.permission.SYSTEM_ALERT_WINDOW,Manifest.permission.GET_ACCOUNTS,Manifest.permission.WRITE_APN_SETTINGS};
            ActivityCompat.requestPermissions(this,mPermissionList,123);
        }
    }

    /*private void testRsa() {
        try {
            PublicKey publicKey = RsaNewUtils.loadPublicKey(Constant.PUBLICKEY);
            PrivateKey privateKey = RsaNewUtils.loadPrivateKey(Constant.privateKey);
            String str = "hello";
            String publicRsa = RsaNewUtils.encryptDataStr(str.getBytes("utf-8"), publicKey);
            byte[] bytes = RsaNewUtils.decryptData(publicRsa.getBytes("utf-8"), privateKey);
            String privateRsa = new String(bytes);
            System.out.println();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }*/

    private void judge() {
        SharedPreferences MSP = getSharedPreferences(Constant.MSP, Context.MODE_PRIVATE);
         String access_token = MSP.getString(Constant.ACCESS_TOKEN, "").trim();

        if(!TextUtils.isEmpty(access_token)){
            startActivity(new Intent(context, MainActivity.class));
            finish();
        }
    }

    LoginView loginView;
    String account;
    private void initView() {

        loginView = findViewById(R.id.loginView);
       /* loginView.setOnLoginClick(new LoginView.OnLoginClick() {
            @Override
            public void onLoginClick() {
                account = loginView.getAccount();
//                getData();
                Intent intent = new Intent(context, MsgActivity.class);
                intent.putExtra("account",account);
                intent.putExtra(MsgActivity.TYPE,MsgActivity.type_tel);
                startActivity(intent);
            }
        });*/


    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

    }
}